package com.leyou.auth.service.controller;

import com.leyou.auth.inter.pojo.UserInfo;
import com.leyou.auth.service.service.AuthService;
import com.leyou.common.bean.Result;
import com.leyou.user.inter.dto.UserLoginDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zqq
 * @ClassName AuthController
 * @Description
 * @date 2020/3/4-17:55
 */
@RestController
@Api(value = "AuthController",description = "登录授权接口")
public class AuthController {

    @Autowired
    private AuthService authService;

    @PostMapping("accredit")
    @ApiOperation(value = "登录授权", notes = "登录授权")
    public Result<String> authentication(@RequestBody UserLoginDTO dto) {
        return this.authService.authentication(dto);
    }

    @GetMapping("verify")
    @ApiOperation(value = "验证用户并返回信息", notes = "验证用户并返回信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "x-authorize-token", dataType = "string", required = true, value = "登陆token") })
    public Result<UserInfo> verifyUser(HttpServletRequest request, HttpServletResponse response){
        return this.authService.verifyUser(request,response);
    }

    @GetMapping("logout")
    @ApiOperation(value = "用户注销", notes = "用户注销")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "x-authorize-token", dataType = "string", required = true, value = "登陆token") })
    public Result logout(HttpServletRequest request){
        return  this.authService.logout(request);
    }

}
